//传入文件大小，根据大小给出kb,m,gb单位的数值
import {useUserInfoStore} from "@/stores/user_info";
//@ts-ignore
import SparkMD5 from 'spark-md5';
import {useFileInfoStore} from "@/stores/file_info";
import {fileChunk, mergeFile, fileCheck, fileUpload} from "@/api/file";
import {ElNotification} from 'element-plus'

//传入文件，文件片数，每片文件大小，返回该文件片






// 主线程切片并计算md5值
// export function chunkFile(file, chunkSize) {
//     const fileInfoStore = useFileInfoStore();
//     let chunkCount = Math.ceil(file.size / chunkSize);
//     let chunks = [];
//     let spark = new SparkMD5.ArrayBuffer;
//     let fileReader = new FileReader();
//     let currentIndex = 0;
//     const load = () => {
//         let start = currentIndex * chunkSize;
//         let end = start + chunkSize;
//         let blob = file.slice(start, end);
//         chunks.push(blob)
//         fileReader.readAsArrayBuffer(blob)
//     }
//     load();
//     return new Promise((resolve, reject) => {
//         fileReader.onload = (res) => {
//             currentIndex++
//             if (currentIndex <= chunkCount) {
//                 spark.append(res.target.result)
//                 load()
//                 fileInfoStore.files[0].analyzeSchedule = Math.floor((currentIndex / chunkCount) * 100);
//             } else {
//                 resolve({
//                     chunks,
//                     has: spark.end()
//                 })
//             }
//
//         }
//     })
// }
